import java.util.Arrays;

public class Test_0220 {
    public static void rotate(int[] nums, int k) {
        if((k %= 7) == 0) {
            System.out.println(Arrays.toString(nums));
            return;
        }
        reverse(nums,0, nums.length - 1);
        reverse(nums, 0, k - 1);
        reverse(nums, k, nums.length - 1);
        System.out.println(Arrays.toString(nums));
    }
    public static void reverse(int[] nums, int begin, int end) {
        while (begin < end) {
            int tmp = nums[begin];
            nums[begin] = nums[end];
            nums[end] = tmp;
            begin++;
            end--;
        }
    }
    public static void main(String[] args) {
        int[] nums = {1,2,3,4,5,6,7};
        rotate(nums,3);
    }
}
//    public int missingNumber(int[] nums) {
//        int n = nums.length;
//        int total = n * (n + 1) / 2;
//        int sum = 0;
//        for(int i = 0; i < n; i++)
//            sum += nums[i];
//        return total - sum;
//    }